﻿namespace DeploymentManagerTests.TestSupport
{
    using System;

    using CloudBlitz.DeploymentManager;
    using CloudBlitz.DeploymentManager.DeploymentWorkflow;

    public class TestDeploymentOperation : DeploymentOperationBase
    {
        private readonly string id = Guid.NewGuid().ToString();
        private readonly bool success;

        public TestDeploymentOperation(int progressWeight, bool success = true) : base(progressWeight)
        {
            this.success = success;
        }

        protected override OperationResult ExecuteOverride(DeploymentContext context)
        {
            if (this.success)
            {
                this.RaiseProgressChangedEvent(0, string.Format("Starting operation {0}", this.id));
                this.RaiseProgressChangedEvent(50, string.Format("Running operation {0}", this.id));
                this.RaiseProgressChangedEvent(100, string.Format("Operation finished {0}", this.id));

                return OperationResult.Success;
            }

            return new OperationResult(DeploymentOperationStatus.Failed, "Deployment operation failed");
        }
    }
}